<template>
  <section>
    <mavon-editor v-loading=loading v-model="value" ref="md" @imgAdd="imgAdd" @save="save" @imgDel="imgDel"
                  :ishljs="true"/>
  </section>
</template>
<script>
/* eslint-disable indent,space-before-function-paren */
import {Upload} from '../../util/util'
  import {getAbout, UpdateAbout} from '../../api/api'
  import {getImageUrl} from '../../api/base'

  export default {
    data() {
      return {
        value: '',
        loading: true,
        id: ''
      }
    },
    methods: {
      imgAdd(pos, file) {
        Upload(file).then(x => {
          this.$refs.md.$img2Url(pos, getImageUrl(x))
        })
      },
      imgDel() {

      },
      submit() {
        this.loading = true
        UpdateAbout({
          _id: this.id,
          content: this.value
        }).then(
          data => {
            this.$message.success('保存成功')
            this.loading = false
          }
        ).catch(
          msg => {
            this.loading = false
          }
        )
      },
      save() {
        this.submit()
      }

    },
    mounted() {
      getAbout().then(
        data => {
          console.log(data)
          this.value = data.content
          this.id = data._id
          this.loading = false
        }
      ).catch()
    }
  }
</script>
<style>

</style>
